package data.join.com.database.bean;

import java.util.List;

import data.join.com.database.GreenDao;

/**
 * Created by Administrator on 2017/9/28.
 */

public class FileNameSyncPref {

    public static int FILE_SYNC_TYPE_VIDEO = 0;
    public static int FILE_SYNC_TYPE_IMAGE = 1;

    public static int FILE_SYNC_ACTION_ADD = 0;
    public static int FILE_SYNC_ACTION_DELETE = 1;

    private static FileNameSyncPref fileNameSyncPref;

    private FileNameSyncDao fileNameSyncDao;

    private FileNameSyncPref(){
        fileNameSyncDao = GreenDao.getInstance().sDaoSession.getFileNameSyncDao();

        FileNameSyncDao.createTable(fileNameSyncDao.getDatabase(),true);
    }

    public static FileNameSyncPref getInstance(){
        if(fileNameSyncPref == null){
            fileNameSyncPref = new FileNameSyncPref();
        }
        return fileNameSyncPref;
    }

    public void insertFile(FileNameSync fileNameSync){
        fileNameSyncDao.insert(fileNameSync);
    }

    public List<FileNameSync> queryAll(){
       return fileNameSyncDao.loadAll();
    }

    public void deleteItem(FileNameSync fileNameSync){
        fileNameSyncDao.deleteByKey(fileNameSync.getId());
    }

    public void insertFileNameSync(VideoBean videoBean,int action){
        FileNameSync fileNameSync = new FileNameSync(null,FileNameSyncPref.FILE_SYNC_TYPE_VIDEO,videoBean.id,action);
        FileNameSyncPref.getInstance().insertFile(fileNameSync);
    }

    public List<FileNameSync> getEarliestFile(){
        return fileNameSyncDao.queryBuilder().orderAsc(FileNameSyncDao.Properties.Id).limit(40).list();
    }
}
